import { IContext, IEntityLocalDataService, IParam } from '@/core';
import { IAvueTest } from '../interface/i-avue-test';
import keys from '../avue-test-keys';
import { AvueChildFourDTOHelp } from '@/api/avue-child-four/dto-help/avue-child-four-helps'
import { AvueChildFiveDTOHelp } from '@/api/avue-child-five/dto-help/avue-child-five-helps'
import { AvueChildOneDTOHelp } from '@/api/avue-child-one/dto-help/avue-child-one-helps'
import { AvueChildThreeDTOHelp } from '@/api/avue-child-three/dto-help/avue-child-three-helps'
import { AvueChildTwoDTOHelp } from '@/api/avue-child-two/dto-help/avue-child-two-helps'

/**
 * AvueTestDTODTO辅助类
 * 基于template/src/api/{{appEntities}}/data-service/{{appEntities}}-help.ts.hbs生成  
 *
 * @export
 * @class AvueTestDTOHelp
 */
export class AvueTestDTOHelp {

    /**
     * 获取实体数据服务
     *
     * @static
     * @param {IParam} context
     * @return {*}  {Promise<IEntityLocalDataService<IAvueTest>>}
     * @memberof AvueTestDTOHelp
     */
    public static async getService(context: IParam): Promise<IEntityLocalDataService<IAvueTest>> {
        return App.getDataService('AvueTest', context);
    }

    /**
     * 获取是否缓存
     *
     * @memberof AvueTestDTOHelp
     */
    public static getEnableCache(){
        return false;
    }

    /**
     * DTO转化成数据对象
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} source dto对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async toDataObj(context: IContext, source: IParam) {
        const _data: any = {};
        //  单行文本
        _data.singlelinetext = source.singlelinetext;
        //  评价
        _data.rate = source.rate;
        //  滑块
        _data.slider = source.slider;
        //  单选列表
        _data.checkbox = source.checkbox;
        //  选项框列表
        _data.checkboxlist = source.checkboxlist;
        //  下拉列表框标准
        _data.dropdownlist = source.dropdownlist;
        //  下拉级联选择
        _data.dropdownlistcascader = source.dropdownlistcascader;
        //  下拉树
        _data.dropdownlisttree = source.dropdownlisttree;
        //  数值框
        _data.inputnumber = source.inputnumber;
        //  地图选择
        _data.mapselect = source.mapselect;
        //  地图经度
        _data.maplongitude = source.maplongitude;
        //  地图纬度
        _data.maplatitude = source.maplatitude;
        //  多行文本
        _data.mutlilinetext = source.mutlilinetext;
        //  密码框
        _data.passwordtext = source.passwordtext;
        //  滑块范围
        _data.sliderrange = source.sliderrange;
        //  单选框按钮
        _data.checkboxbutton = source.checkboxbutton;
        //  选项框按钮
        _data.checkboxlistbutton = source.checkboxlistbutton;
        //  多选下拉
        _data.mutlidropdownlist = source.mutlidropdownlist;
        //  多选下拉级联
        _data.mutlidropdownlistcascader = source.mutlidropdownlistcascader;
        //  多选下拉树
        _data.mutlidropdownlisttree = source.mutlidropdownlisttree;
        //  级联一层
        _data.cascaderone = source.cascaderone;
        //  级联二层
        _data.cascadertwo = source.cascadertwo;
        //  级联树
        _data.cascadertree = source.cascadertree;
        //  级联选择
        _data.cascaderselect = source.cascaderselect;
        //  属性
        _data.mutlicascaderselect = source.mutlicascaderselect;
        //  多选树
        _data.mutlicascadertree = source.mutlicascadertree;
        //  字符串数组
        _data.stringarray = source.stringarray;
        //  URL数组
        _data.urlarray = source.urlarray;
        //  图片数组
        _data.imagearray = source.imagearray;
        //  数值数组
        _data.numberarray = source.numberarray;
        //  时间范围
        _data.timerange = source.timerange;
        //  日期范围
        _data.daterange = source.daterange;
        //  数值范围
        _data.numberrange = source.numberrange;
        //  启动时间
        _data.starttime = source.starttime;
        //  结束时间
        _data.endtime = source.endtime;
        //  结束日期
        _data.enddate = source.enddate;
        //  开始日期
        _data.startdate = source.startdate;
        //  开始数值
        _data.startnumber = source.startnumber;
        //  结束数值
        _data.endnumber = source.endnumber;
        //  孩子数据
        _data.avuechildfours = source.avuechildfours;
        //  avuechildfours
        if(AvueChildFourDTOHelp.getEnableCache()){
            if (source && source.avuechildfours && source.avuechildfours.length > 0) {
                await AvueChildFourDTOHelp.setCacheDataArray(context, source.avuechildfours);
            }
        }else{
            _data.avuechildfours = source.avuechildfours;
        }
        //  开关
        _data.switchfield = source.switchfield;
        //  整型数组
        _data.intarray = source.intarray;
        //  avue测试标识
        _data.avuetestid = source.avuetestid;
        //  avue测试名称
        _data.avuetestname = source.avuetestname;
        //  建立时间
        _data.createdate = source.createdate;
        //  建立人
        _data.createman = source.createman;
        //  更新时间
        _data.updatedate = source.updatedate;
        //  更新人
        _data.updateman = source.updateman;
        //  avuechildfives
        if(AvueChildFiveDTOHelp.getEnableCache()){
            if (source && source.avuechildfives && source.avuechildfives.length > 0) {
                await AvueChildFiveDTOHelp.setCacheDataArray(context, source.avuechildfives);
            }
        }else{
            _data.avuechildfives = source.avuechildfives;
        }
        //  avuechildones
        if(AvueChildOneDTOHelp.getEnableCache()){
            if (source && source.avuechildones && source.avuechildones.length > 0) {
                await AvueChildOneDTOHelp.setCacheDataArray(context, source.avuechildones);
            }
        }else{
            _data.avuechildones = source.avuechildones;
        }
        //  avuechildthrees
        if(AvueChildThreeDTOHelp.getEnableCache()){
            if (source && source.avuechildthrees && source.avuechildthrees.length > 0) {
                await AvueChildThreeDTOHelp.setCacheDataArray(context, source.avuechildthrees);
            }
        }else{
            _data.avuechildthrees = source.avuechildthrees;
        }
        //  avuechildtwos
        if(AvueChildTwoDTOHelp.getEnableCache()){
            if (source && source.avuechildtwos && source.avuechildtwos.length > 0) {
                await AvueChildTwoDTOHelp.setCacheDataArray(context, source.avuechildtwos);
            }
        }else{
            _data.avuechildtwos = source.avuechildtwos;
        }
        //  处理预置字段（以srf开头）
        if (source && Object.keys(source).length > 0) {
            Object.keys(source).forEach((key:string) =>{
                if(key.startsWith('srf')){
                    _data[key] = source[key];
                }
            })
        }
        return _data;
    }

    /**
     * 转化数据（DTO转化成数据对象）
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} data 数据对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async toDataObjArray(context: IContext, data: any[]) {
        const _data: any[] = [];
        if (data && Array.isArray(data) && data.length > 0) {
            for (let i = 0; i < data.length; i++) {
                const tempdata = await this.toDataObj(context, data[i]);
                _data.push(tempdata);
            }
        }
        return _data;
    }

    /**
     * 数据对象转化成DTO
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} source 数据对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async toDto(context: IContext, source: IParam) {
        const _data: any = {};
        const excludes: string[] = ['avuechildfours', 'avuechildfives', 'avuechildones', 'avuechildthrees', 'avuechildtwos'];
        //  单行文本
        if(source.hasOwnProperty('singlelinetext')){
            _data.singlelinetext = source.singlelinetext;
        }
        //  评价
        if(source.hasOwnProperty('rate')){
            _data.rate = source.rate;
        }
        //  滑块
        if(source.hasOwnProperty('slider')){
            _data.slider = source.slider;
        }
        //  单选列表
        if(source.hasOwnProperty('checkbox')){
            _data.checkbox = source.checkbox;
        }
        //  选项框列表
        if(source.hasOwnProperty('checkboxlist')){
            _data.checkboxlist = source.checkboxlist;
        }
        //  下拉列表框标准
        if(source.hasOwnProperty('dropdownlist')){
            _data.dropdownlist = source.dropdownlist;
        }
        //  下拉级联选择
        if(source.hasOwnProperty('dropdownlistcascader')){
            _data.dropdownlistcascader = source.dropdownlistcascader;
        }
        //  下拉树
        if(source.hasOwnProperty('dropdownlisttree')){
            _data.dropdownlisttree = source.dropdownlisttree;
        }
        //  数值框
        if(source.hasOwnProperty('inputnumber')){
            _data.inputnumber = source.inputnumber;
        }
        //  地图选择
        if(source.hasOwnProperty('mapselect')){
            _data.mapselect = source.mapselect;
        }
        //  地图经度
        if(source.hasOwnProperty('maplongitude')){
            _data.maplongitude = source.maplongitude;
        }
        //  地图纬度
        if(source.hasOwnProperty('maplatitude')){
            _data.maplatitude = source.maplatitude;
        }
        //  多行文本
        if(source.hasOwnProperty('mutlilinetext')){
            _data.mutlilinetext = source.mutlilinetext;
        }
        //  密码框
        if(source.hasOwnProperty('passwordtext')){
            _data.passwordtext = source.passwordtext;
        }
        //  滑块范围
        if(source.hasOwnProperty('sliderrange')){
            _data.sliderrange = source.sliderrange;
        }
        //  单选框按钮
        if(source.hasOwnProperty('checkboxbutton')){
            _data.checkboxbutton = source.checkboxbutton;
        }
        //  选项框按钮
        if(source.hasOwnProperty('checkboxlistbutton')){
            _data.checkboxlistbutton = source.checkboxlistbutton;
        }
        //  多选下拉
        if(source.hasOwnProperty('mutlidropdownlist')){
            _data.mutlidropdownlist = source.mutlidropdownlist;
        }
        //  多选下拉级联
        if(source.hasOwnProperty('mutlidropdownlistcascader')){
            _data.mutlidropdownlistcascader = source.mutlidropdownlistcascader;
        }
        //  多选下拉树
        if(source.hasOwnProperty('mutlidropdownlisttree')){
            _data.mutlidropdownlisttree = source.mutlidropdownlisttree;
        }
        //  级联一层
        if(source.hasOwnProperty('cascaderone')){
            _data.cascaderone = source.cascaderone;
        }
        //  级联二层
        if(source.hasOwnProperty('cascadertwo')){
            _data.cascadertwo = source.cascadertwo;
        }
        //  级联树
        if(source.hasOwnProperty('cascadertree')){
            _data.cascadertree = source.cascadertree;
        }
        //  级联选择
        if(source.hasOwnProperty('cascaderselect')){
            _data.cascaderselect = source.cascaderselect;
        }
        //  属性
        if(source.hasOwnProperty('mutlicascaderselect')){
            _data.mutlicascaderselect = source.mutlicascaderselect;
        }
        //  多选树
        if(source.hasOwnProperty('mutlicascadertree')){
            _data.mutlicascadertree = source.mutlicascadertree;
        }
        //  字符串数组
        if(source.hasOwnProperty('stringarray')){
            _data.stringarray = source.stringarray;
        }
        //  URL数组
        if(source.hasOwnProperty('urlarray')){
            _data.urlarray = source.urlarray;
        }
        //  图片数组
        if(source.hasOwnProperty('imagearray')){
            _data.imagearray = source.imagearray;
        }
        //  数值数组
        if(source.hasOwnProperty('numberarray')){
            _data.numberarray = source.numberarray;
        }
        //  时间范围
        if(source.hasOwnProperty('timerange')){
            _data.timerange = source.timerange;
        }
        //  日期范围
        if(source.hasOwnProperty('daterange')){
            _data.daterange = source.daterange;
        }
        //  数值范围
        if(source.hasOwnProperty('numberrange')){
            _data.numberrange = source.numberrange;
        }
        //  启动时间
        if(source.hasOwnProperty('starttime')){
            _data.starttime = source.starttime;
        }
        //  结束时间
        if(source.hasOwnProperty('endtime')){
            _data.endtime = source.endtime;
        }
        //  结束日期
        if(source.hasOwnProperty('enddate')){
            _data.enddate = source.enddate;
        }
        //  开始日期
        if(source.hasOwnProperty('startdate')){
            _data.startdate = source.startdate;
        }
        //  开始数值
        if(source.hasOwnProperty('startnumber')){
            _data.startnumber = source.startnumber;
        }
        //  结束数值
        if(source.hasOwnProperty('endnumber')){
            _data.endnumber = source.endnumber;
        }
        //  孩子数据
        if(source.hasOwnProperty('avuechildfours')){
            _data.avuechildfours = source.avuechildfours;
        }
        //  avuechildfours
        if(AvueChildFourDTOHelp.getEnableCache()){
            _data.avuechildfours = await AvueChildFourDTOHelp.getCacheDataArray(context);
        }else{
            if(source.hasOwnProperty('avuechildfours')){
                _data.avuechildfours = source.avuechildfours;
            }
        }
        //  开关
        if(source.hasOwnProperty('switchfield')){
            _data.switchfield = source.switchfield;
        }
        //  整型数组
        if(source.hasOwnProperty('intarray')){
            _data.intarray = source.intarray;
        }
        //  avue测试标识
        if(source.hasOwnProperty('avuetestid')){
            _data.avuetestid = source.avuetestid;
        }
        //  avue测试名称
        if(source.hasOwnProperty('avuetestname')){
            _data.avuetestname = source.avuetestname;
        }
        //  建立时间
        if(source.hasOwnProperty('createdate')){
            _data.createdate = source.createdate;
        }
        //  建立人
        if(source.hasOwnProperty('createman')){
            _data.createman = source.createman;
        }
        //  更新时间
        if(source.hasOwnProperty('updatedate')){
            _data.updatedate = source.updatedate;
        }
        //  更新人
        if(source.hasOwnProperty('updateman')){
            _data.updateman = source.updateman;
        }
        //  avuechildfives
        if(AvueChildFiveDTOHelp.getEnableCache()){
            _data.avuechildfives = await AvueChildFiveDTOHelp.getCacheDataArray(context);
        }else{
            if(source.hasOwnProperty('avuechildfives')){
                _data.avuechildfives = source.avuechildfives;
            }
        }
        //  avuechildones
        if(AvueChildOneDTOHelp.getEnableCache()){
            _data.avuechildones = await AvueChildOneDTOHelp.getCacheDataArray(context);
        }else{
            if(source.hasOwnProperty('avuechildones')){
                _data.avuechildones = source.avuechildones;
            }
        }
        //  avuechildthrees
        if(AvueChildThreeDTOHelp.getEnableCache()){
            _data.avuechildthrees = await AvueChildThreeDTOHelp.getCacheDataArray(context);
        }else{
            if(source.hasOwnProperty('avuechildthrees')){
                _data.avuechildthrees = source.avuechildthrees;
            }
        }
        //  avuechildtwos
        if(AvueChildTwoDTOHelp.getEnableCache()){
            _data.avuechildtwos = await AvueChildTwoDTOHelp.getCacheDataArray(context);
        }else{
            if(source.hasOwnProperty('avuechildtwos')){
                _data.avuechildtwos = source.avuechildtwos;
            }
        }
        // 附加额外数据
        if (source && Object.keys(source).length > 0 && keys) {
            Object.keys(source).forEach((key: string) => {
                if (!keys.includes(key) && !excludes.includes(key)) {
                    _data[key] = source[key];
                }
            })
        }
        return _data;
    }

    /**
     * 转化数组(数据对象转化成DTO数组)
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam[]} data 数据对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async toDtoArray(context: IContext, data: IParam[]) {
        const _data: any[] = [];
        if (data && Array.isArray(data) && data.length > 0) {
            for (let i = 0; i < data.length; i++) {
                const tempdata = await this.toDto(context, data[i]);
                _data.push(tempdata);
            }
        }
        return _data;
    }

    /**
     * 处理响应DTO对象
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} data 数据对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async set(context: IContext, data: IParam) {
        const _data: IParam = await this.toDataObj(context, data);
        return _data;
    }

    /**
     * 处理请求数据对象
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} data 数据对象
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async get(context: IContext, data: IParam = {}) {
        return await this.toDto(context, data);
    }

    /**
     * 获取缓存数据
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {string} srfkey 数据主键
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async getCacheData(context: IContext, srfkey: string) {
        return {};
    }

    /**
     * 获取缓存数组
     *
     * @static
     * @param {IContext} context 应用上下文
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async getCacheDataArray(context: IContext) {
        return [];
    }

    /**
     * 设置缓存数据
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {IParam} data 数据
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async setCacheData(context: IContext, data: IParam) {
    }

    /**
     * 设置缓存数组
     *
     * @static
     * @param {IContext} context 应用上下文
     * @param {any[]} data 数据
     * @return {*} 
     * @memberof AvueTestDTOHelp
     */
    public static async setCacheDataArray(context: IContext, data: any[]) {
    }
}
